package com.tg.message.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tg.message.R;

public class DateAdapter extends RecyclerView.Adapter<DateAdapter.MessageDateViewHolder> {
    protected Context  context;
    protected int selectedDay;
    private OnDateItemListener onDateItemListener;

    public DateAdapter() {

    }

    public void setOnDateItemListener(OnDateItemListener onDateItemListener) {
        this.onDateItemListener = onDateItemListener;
    }

    public int getSelectedDay() {
        return selectedDay;
    }

    public void setSelectedDay(int selectedDay) {
        this.selectedDay = selectedDay;
    }


    @NonNull
    @Override
    public DateAdapter.MessageDateViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.layout_message_date_item_for_message_activity, parent, false);
        return new MessageDateViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DateAdapter.MessageDateViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        if (selectedDay == position) {
            holder.dateText.setTextColor(context.getResources().getColor(R.color.global_customize_fixed_color_link));
        } else {
            holder.dateText.setTextColor(context.getResources().getColor(R.color.global_message_noselected_color));
        }

        holder.itemView.setOnClickListener(view -> {
            selectedDay = position;
            if (onDateItemListener != null) {
                onDateItemListener.onClick(position);
            }
            notifyDataSetChanged();
        });
    }


    @Override
    public int getItemCount() {
        return 0;
    }

    public static class MessageDateViewHolder extends RecyclerView.ViewHolder {
        TextView dateText;
        public MessageDateViewHolder(@NonNull View itemView) {
            super(itemView);
            dateText = itemView.findViewById(R.id.tv_playback_date_day);
        }
    }

    public interface OnDateItemListener {
        void onClick(int position);
    }
}
